package com.javaweb.config;

import com.javaweb.interceptor.LoginInterceptor;
import com.javaweb.interceptor.RoomEnterInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private RoomEnterInterceptor roomEnterInterceptor;

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截路径
        //  '/*'  匹配一级路径 比如/dept, /emp 不能匹配 /dept/1, /emp/dept
        //  '/**'  匹配任意路径
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") //  '/**' 表示拦截所有请求
                .excludePathPatterns("/user/login") //表示不拦截登录请求
                .excludePathPatterns("/user/register"); //表示不拦截注册请求

        registry.addInterceptor(roomEnterInterceptor)
                .addPathPatterns("/room/*")
                .excludePathPatterns("/room/listAll")
                .excludePathPatterns("/room/listMine");
    }
}
